package com.business_clean.viewmodel.request

import androidx.lifecycle.MutableLiveData
import com.business_clean.app.network.NetUrl
import com.business_clean.data.mode.login.CodeEntity
import com.business_clean.data.mode.login.UserInfo
import me.hgj.mvvmhelper.base.BaseViewModel
import me.hgj.mvvmhelper.ext.rxHttpRequest
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 登录的接口请求
 */
class LoginVideModel : BaseViewModel() {

    var codeEntity = MutableLiveData<CodeEntity>()
    var userInfo = MutableLiveData<UserInfo>()

    var selectUserInfo = MutableLiveData<UserInfo>()

    /**
     * 获取验证码
     */
    fun getLoginCode(mobile: String) {
        rxHttpRequest {
            onRequest = {
                codeEntity.value = RxHttp.get(NetUrl.GET_LOGIN_CODE)
                    .add("mobile", mobile)
                    .toResponse<CodeEntity>().await()
            }
        }

        rxHttpRequest {
            onRequest = {
                codeEntity.value = RxHttp.get(NetUrl.GET_LOGIN_CODE)
                    .add("mobile", mobile)
                    .toResponse<CodeEntity>().await()
            }
        }
    }

    /**
     * 登录
     */
    fun loginApp(hashMap: HashMap<String, String>) {

        rxHttpRequest {
            onRequest = {
                userInfo.value = RxHttp.get(NetUrl.LOGIN_SIGN_IN)
                    .addAll(hashMap)
                    .toResponse<UserInfo>().await()
            }
        }
    }


    /**
     * 登录
     */
    fun loginAliApp(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                userInfo.value = RxHttp.get(NetUrl.GET_ALI_SING_IN)
                    .addAll(hashMap)
                    .toResponse<UserInfo>().await()
            }
        }
    }


    /**
     * 确定企业的信息
     */
    fun requestCompany(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                selectUserInfo.value = RxHttp.get(NetUrl.SELECT_COMPANY)
                    .addAll(hashMap)
                    .toResponse<UserInfo>().await()
            }
        }
    }
}